package net.sisgac.atencion_cliente.model.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import net.sisgac.atencion_cliente.model.Destinatario;
import net.sisgac.atencion_cliente.model.dao.DestinatarioDAO;


@SuppressWarnings("unchecked")
public class JPADestinatarioDAO implements DestinatarioDAO {
	
	private EntityManager em;

	
	public JPADestinatarioDAO(EntityManager em){
		this.em=em;
	}
	
	
	public List<Destinatario> findAll() {
		// TODO Auto-generated method stub
		Query query=em.createQuery("SELECT o FROM DESTINATARIO o");
		return query.getResultList();
	}
	
	public Destinatario findById(String id) {
		Query query=em.createQuery("SELECT o FROM DESTINATARIO o WHERE IDDESTINATARIO=:id");
		query.setParameter(id, id);
		return (Destinatario) query.getResultList();
	}
	
	public Destinatario find(Destinatario o) {
		// TODO Auto-generated method stub
		Query query=em.createQuery("SELECT o FROM DESTINATARIO o WHERE o.nombreDestinatario=?1");
		query.setParameter(1, o.getNombredestinatario());
		return (Destinatario)query.getSingleResult();
	}
}
